<?php
session_start();
include_once("check_login.php");
if ($_SESSION["power_code"] != "admin") {
	header("location:index.php");
	exit();
}
include_once("class/common.fun.php");
include_once("class/MySqlConnect.class.php");

$auction_id = $_GET['auction_id'] ;
if (empty($auction_id)) {
	showMessage("Operation of an error");
}
if (!is_numeric($auction_id)) {
	showMessage("Operation of an error");
}

if (isset($_POST['active'])) {
	$active = $_POST['active'];
	if ($active == "mod_auction") {
		$auction_code = trim($_POST['auction_code']);
		$auction_content = trim($_POST['auction_content']);
		$lowest_price = trim($_POST['lowest_price']);
		$at_term = trim($_POST['at_term']);
		
		if (empty($auction_code)) {
			showMessage("Please enter the item code");
		}
		
		if (empty($auction_content)) {
			showMessage("Please enter a Project Description");
		}
		
		if (empty($lowest_price) || (!is_numeric($lowest_price))) {
			showMessage("Please enter a minimum price");
		}
		
		if (empty($at_term)) {
			showMessage("Please enter a cut-off time");
		}
		
		$_MySqlConnect = new MySqlConnect();
		$sql = "SELECT * FROM auction where auction_code = '".$auction_code."' and auction_id != $auction_id LIMIT 0,1";
		$arr = $_MySqlConnect->execute($sql);
		if (!empty($arr)) {
			showMessage("Please enter the item code duplication");
		}
		
		$_MySqlConnect->update("auction", array("auction_code"=>$auction_code,"auction_content"=>$auction_content,"lowest_price"=>$lowest_price,"at_term"=>$at_term), array("auction_id"=>$auction_id));
		
		showMessage("Successfully modified","GoUrl","list.php");
	}	
}




$_MySqlConnect = new MySqlConnect();
$sql = "SELECT * FROM auction where auction_id = ".$auction_id." LIMIT 0,1";
$arr_list = $_MySqlConnect->execute($sql);
if (empty($arr_list)) {
	showMessage("Operation of an error");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Changes</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php include("menu.php"); ?>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="">
<input name="active" type="hidden" value="mod_auction">
<input name="auction_id" type="hidden" value="<?php echo $auction_id;?>">
  <tr>
    <td width="111" height="30"><SPAN id="result_box"><SPAN  closure_hashCode_4om4wx="18">Item   Code</SPAN></SPAN>:</td>
    <td width="489"><label>
      <input name="auction_code" type="text" id="auction_code" value="<?php echo $arr_list[0]['auction_code'];?>">
    </label></td>
  </tr>
  
  <tr>
    <td height="30">Lowest   price:</td>
    <td><label>
      <input name="lowest_price" type="text" id="lowest_price" value="<?php echo $arr_list[0]['lowest_price'];?>">
    </label></td>
  </tr>
  <tr>
    <td height="30">Auction cut-off   time:</td>
    <td><label>
      <input name="at_term" type="text" id="at_term" value="<?php echo $arr_list[0]['at_term'];?>">
    </label></td>
  </tr>
  <tr>
    <td height="30">Project   Description:</td>
    <td><label>
      <textarea name="auction_content" cols="60" rows="6" id="auction_content"><?php echo $arr_list[0]['auction_content'];?></textarea>
    </label></td>
  </tr>
  <tr>
    <td height="30" colspan="2">
	<div align="center">
      <label>
        <input type="submit" name="Submit" value="Submit">
&nbsp;&nbsp;&nbsp; </label>
      <label>
      <input type="reset" name="Submit2" value="Reset">
      </label>
      </div>     </td>
  </tr>
  </form>
</table>
</body>
</html>
